package cn.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * Created by wsx on 2017/1/25.
 */
@Service
public class EmailService {
    @Autowired
    private JavaMailSender javaMailSender;
    @Autowired
    private SimpleMailMessage simpleMailMessage;
    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    /**
     * 使用 emailService.Send("860223178@qq.com","测试标题","测试内容");
     * @param to
     * @param subject
     * @param text
     */
    public void Send(String to,String subject,String text){
        taskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                simpleMailMessage.setTo(to);
                simpleMailMessage.setSubject(subject);
                simpleMailMessage.setText(text);
                javaMailSender.send(simpleMailMessage);
            }
        });
    }

}
